<template>
  <div>
    <a-card :bordered="false">

      <f-table ref="table" size="default" rowKey="payId" :columns="columns" :multiple="false" :operator="operator" :params="queryParam" :api="api.payconfig">
          <span slot="payLogo" slot-scope="text, record, index">
          <img v-lazy="record.payLogo" v-viewer class="radius-img">
        </span>
        <span slot="payStatus" slot-scope="text, record, index">
          <a-switch v-model="record.payStatus==1" checkedChildren="启用" unCheckedChildren="禁用" @change="(checked) => setStatus(checked,record)"/>
        </span>
        <span slot="isTest" slot-scope="text, record, index">
          <a-switch v-model="record.isTest==1" checkedChildren="启用" unCheckedChildren="禁用" @change="(checked) => setIsTest(checked,record)"/>
        </span>
        <span slot="action" slot-scope="text, record">
          <template>
            <a @click="$refs.modal.handleShow(record)">编辑</a>
          </template>
        </span>
      </f-table>
      <pay-config-drawer ref="modal"></pay-config-drawer>
    </a-card>
  </div>
</template>

<script>

  import PayConfigDrawer from './payconfig_drawer'

  export default {
    name: 'TableList',
    components: {
      PayConfigDrawer

    },
    data () {
      let me = this
      return {
        //列表初始化查询参数
        queryParam: {},
        // 表头
        columns: [
          {
            title: 'Logo',
            align: 'center',
            scopedSlots: { customRender: 'payLogo' }
          },
          {
            title: '支付名称',
            align: 'center',
            dataIndex: 'payName'
          },
          {
            title: 'AppID',
            align: 'center',
            dataIndex: 'appId'
          },
          {
            title: '启用状态',
            align: 'center',
            dataIndex: 'payStatus',
            scopedSlots: { customRender: 'payStatus' }
          },
          {
            title: '测试环境',
            align: 'center',
            dataIndex: 'isTest',
            scopedSlots: { customRender: 'isTest' }
          },
          {
            title: '操作',
            dataIndex: 'action',
            scopedSlots: { customRender: 'action' }
          }
        ],
        //操作按钮
        operator: [
        ]
      }
    },
    created () {

    },
    methods: {
      setStatus (check, record) {
        this.http.post(this, {
          url: this.api.payconfig.setPayStatus,
          data: {
            ids: record.payId,
            payStatus: Number(check)
          },
          success (me, data) {
            record.payStatus = data
          }
        })
      },
      setIsTest (check, record) {
        this.http.post(this, {
          url: this.api.payconfig.setIsTest,
          data: {
            ids: record.payId,
            isTest: Number(check)
          },
          success (me, data) {
            record.isTest = data
          }
        })
      }
    }
  }
</script>
